home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / Epic4_mos / share / epic / script / epic-crypt-gpg-aa < prev    next >
Encoding:
Text File  |  2002-10-28  |  1.4 KB  |  48 lines

  1. #!/bin/bash
  2. #
  3. # This script demonstrates ascii armoring.  It is rather complicated
  4. # because it uses the ascii armoring present in gpg, which wraps in
  5. # a way that is unusable for irc.  One of the things that can be
  6. # done is to join all the cyphertext lines together, and reformat
  7. # them into a valid gpg message again at the other end.
  8. #
  9. # Decryption is a little tricky.  What we do is create a token ascii
  10. # armored gpg message, strip it of the message content, fill it in
  11. # with the reformatted message and pipe it back into gpg for
  12. # decryption.
  13. #
  14. # Since the plaintext and cyphertext are read in non-newline binary
  15. # mode, echo -n is used.
  16.  
  17. function encrypt {
  18.     ( echo "$KEY" ; cat ) | gpg -ca -z 9 --batch --passphrase-fd 0 | (
  19.         while read && [ -n "$REPLY" ] ; do : ; done
  20.         while read && [ -n "$REPLY" ] ; do
  21.             [ -n "$LAST" ] && echo -n "$LAST " ;
  22.             LAST="$REPLY"
  23.         done
  24.     )
  25. }
  26.  
  27. function decrypt {
  28.     read -a input
  29.     ( echo x | gpg -ca --batch --passphrase-fd 0 | (
  30.         while read && [ -n "$REPLY" ] ; do echo "$REPLY" ; done
  31.         while read && [ -n "$REPLY" ] ; do LAST="$REPLY" ; done
  32.         echo
  33.         for foo in "${input[@]}" ; do echo "$foo" ; done
  34.         echo "$LAST"
  35.     ) ) | ( echo "$KEY" ; cat ) | gpg -a --batch --passphrase-fd 0
  36. }
  37.  
  38. proto="$1"
  39. shift 1
  40.  
  41. read KEY TRASH
  42.  
  43. case "$proto" in
  44. encrypt) encrypt "$@" ;;
  45. decrypt) decrypt "$@" ;;
  46. *)    echo `basename $0` "{encrypt|decrypt} < text" 1>&2 ;;
  47. esac
  48.